import unittest
from common.functions import open_browser
from page.login_page import LoginPage
from page.index_page import IndexPage


class LoginTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 1.打开浏览器
        driver = open_browser()
        # 2.创建了loginpage对象
        cls.login = LoginPage(driver)
        cls.index = IndexPage(driver)

    def test_01_login(self):
        # 请求目标网址
        self.login.get('https://ecshop.test2.shopex123.com/user.php')
        # 3.登录操作
        self.login.input_username('fine1')
        self.login.input_password('123456')
        self.login.input_remember()
        self.login.input_submit()
        # 4.断言登录成功

        username = self.index.font_text()
        self.assertEqual('fine1', username)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.login.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)
